package org.webdb.service.impl;

import java.util.List;

import org.webdb.core.Document;
import org.webdb.core.Filter;
import org.webdb.core.Result;
import org.webdb.core.database.DataBase;
import org.webdb.core.database.Record;
import org.webdb.service.SearchDocumentService;

public class SearchDocumentServiceImpl implements SearchDocumentService {

    @Override
    public List<Document> listDocuments(DataBase database) {
        return database.getDocuments();
    }

    @Override
    public Result<Record> queryDocument(DataBase database, String clusterName,
            String documentName, Filter filter) {

        Document document = database.getDocument(clusterName, documentName);
        if (filter != null)
            return document.getRecords(filter);
        else
            return document.getRecords();
    }

    @Override
    public Result<Record> queryDocument(DataBase database, String documentName,
            Filter filter) {
        return queryDocument(database, null, documentName, filter);
    }

}
